package com.jhh.pay.driver.pojo;

import java.lang.reflect.Type;
import java.util.Map;

import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.parser.DefaultJSONParser;
import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;

import lombok.Data;

@Data
public class PayResponse {
	
	@JSONField(deserializeUsing=StateDeserializer.class)
	private State state;
	
	private int code;
	
	private String msg;
	
	private Map<String, String> extension;
	
	private static class StateDeserializer implements ObjectDeserializer {

		@Override
		@SuppressWarnings("unchecked")
		public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
			return (T) State.getByString(parser.getInput());
		}

		@Override
		public int getFastMatchToken() {
			return 0;
		}

	}

	public static PayResponse localFailed() {
		PayResponse res = new PayResponse();
		res.state = State.FAILED;
		res.code = -1;
		res.msg = "远程接口调用失败";
		return res;
	}

}
